package com.space.rabbitmq.config;

import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 队列配置  可以配置多个队列，消费者配置队列，
 *          可以防止启动时候对于未配置的队列监听不到而报错
 *
 * @author zhanglei
 */
@Configuration
public class QueueConfig {

    @Bean
    public Queue firstQueue() {
        return new Queue(RabbitMqConfig.QUEUE_NAME1, true, false, false);
    }

    @Bean
    public Queue secondQueue() {
        return new Queue(RabbitMqConfig.QUEUE_NAME2, true, false, false);
    }

    @Bean
    public Queue thirdQueue() {
        return new Queue(RabbitMqConfig.QUEUE_NAME3, true, false, false);
    }

    @Bean
    public Queue fourthQueue() {
        return new Queue(RabbitMqConfig.QUEUE_NAME4, true, false, false);
    }

    /**
     * 为fifthQueue配置延迟队列，配置延迟交换机 和 延迟routing-key
     *
     * @return
     */
    @Bean
    public Queue fifthQueue() {
        Map<String, Object> params = new HashMap<>(16);
        params.put("x-dead-letter-exchange", RabbitMqConfig.EXCHANGE_ONE_DEAD);
        params.put("x-dead-letter-routing-key", RabbitMqConfig.ROUTINGKEY_DELAY1);
        params.put("x-message-ttl", RabbitMqConfig.DELAY_TIME);
        return new Queue(RabbitMqConfig.QUEUE_NAME5, true, false, false, params);
    }

    /**
     * 为sixthQueue配置死信队列，配置死信交换机 和 死信routing-key
     *
     * @return
     */
    @Bean
    public Queue sixthQueue() {
        Map<String, Object> params = new HashMap<>(16);
        params.put("x-dead-letter-exchange", RabbitMqConfig.EXCHANGE_ONE_DEAD);
        params.put("x-dead-letter-routing-key", RabbitMqConfig.ROUTINGKEY_DEAD1);
        return new Queue(RabbitMqConfig.QUEUE_NAME6, true, false, false, params);
    }

    /**
     * 死信队列1
     *
     * @return
     */
    @Bean
    public Queue firstDeadQueue() {
        return new Queue(RabbitMqConfig.QUEUE_NAME_DEAD1, true, false, false);
    }

    /**
     * 延迟队列1
     *
     * @return
     */
    @Bean
    public Queue firstDelayQueue() {
        return new Queue(RabbitMqConfig.QUEUE_NAME_DELAY1, true, false, false);
    }
}
